package com.wtp.wallpaper.controller.user;

import com.wtp.wallpaper.annotation.ReplaceURL;
import com.wtp.wallpaper.common.constant.PictureOssPathConstant;
import com.wtp.wallpaper.pojo.result.Result;
import com.wtp.wallpaper.pojo.vo.PictureVO;
import com.wtp.wallpaper.utils.AliOssUtil;
import com.wtp.wallpaper.utils.ai.XFXHUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.UUID;

@RestController
@RequestMapping("/ai")
public class AIController {

    @Autowired
    private XFXHUtil xfxhUtil;

    @Autowired
    private AliOssUtil aliOssUtil;

    @ReplaceURL
    @GetMapping("/generateImage")
    public Result generateImage(String prompt) throws Exception{
        byte[] bytes = xfxhUtil.generateImage(prompt);
        String imgName = UUID.randomUUID().toString().replace("-","") + ".png";
        String imgPath = PictureOssPathConstant.PIC_AI_URL + "/" + imgName;
        aliOssUtil.upload(bytes,imgPath);
        PictureVO pictureVO = new PictureVO();
        pictureVO.setPicurl(imgPath);
        return Result.success(List.of(pictureVO));
    }
}
